/**
 * This is my code.
 *
 * $Id$
 */
package fi.jab.esb.config.xml.impl;

import fi.jab.esb.config.xml.Listener;
import fi.jab.esb.config.xml.PropertyType;
import fi.jab.esb.config.xml.XmlPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Listener</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link fi.jab.esb.config.xml.impl.ListenerImpl#getProperty <em>Property</em>}</li>
 *   <li>{@link fi.jab.esb.config.xml.impl.ListenerImpl#getBusidref <em>Busidref</em>}</li>
 *   <li>{@link fi.jab.esb.config.xml.impl.ListenerImpl#isIsGateway <em>Is Gateway</em>}</li>
 *   <li>{@link fi.jab.esb.config.xml.impl.ListenerImpl#getMaxThreads <em>Max Threads</em>}</li>
 *   <li>{@link fi.jab.esb.config.xml.impl.ListenerImpl#getName <em>Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ListenerImpl extends EObjectImpl implements Listener
{
  /**
   * The cached value of the '{@link #getProperty() <em>Property</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getProperty()
   * @generated
   * @ordered
   */
  protected EList<PropertyType> property;

  /**
   * The default value of the '{@link #getBusidref() <em>Busidref</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getBusidref()
   * @generated
   * @ordered
   */
  protected static final String BUSIDREF_EDEFAULT = "$not-defined$";

  /**
   * The cached value of the '{@link #getBusidref() <em>Busidref</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getBusidref()
   * @generated
   * @ordered
   */
  protected String busidref = BUSIDREF_EDEFAULT;

  /**
   * This is true if the Busidref attribute has been set.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   * @ordered
   */
  protected boolean busidrefESet;

  /**
   * The default value of the '{@link #isIsGateway() <em>Is Gateway</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isIsGateway()
   * @generated
   * @ordered
   */
  protected static final boolean IS_GATEWAY_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isIsGateway() <em>Is Gateway</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isIsGateway()
   * @generated
   * @ordered
   */
  protected boolean isGateway = IS_GATEWAY_EDEFAULT;

  /**
   * This is true if the Is Gateway attribute has been set.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   * @ordered
   */
  protected boolean isGatewayESet;

  /**
   * The default value of the '{@link #getMaxThreads() <em>Max Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxThreads()
   * @generated
   * @ordered
   */
  protected static final int MAX_THREADS_EDEFAULT = 1;

  /**
   * The cached value of the '{@link #getMaxThreads() <em>Max Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxThreads()
   * @generated
   * @ordered
   */
  protected int maxThreads = MAX_THREADS_EDEFAULT;

  /**
   * This is true if the Max Threads attribute has been set.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   * @ordered
   */
  protected boolean maxThreadsESet;

  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ListenerImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return XmlPackage.Literals.LISTENER;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<PropertyType> getProperty()
  {
    if (property == null)
    {
      property = new EObjectContainmentEList<PropertyType>(PropertyType.class, this, XmlPackage.LISTENER__PROPERTY);
    }
    return property;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getBusidref()
  {
    return busidref;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setBusidref(String newBusidref)
  {
    String oldBusidref = busidref;
    busidref = newBusidref;
    boolean oldBusidrefESet = busidrefESet;
    busidrefESet = true;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, XmlPackage.LISTENER__BUSIDREF, oldBusidref, busidref, !oldBusidrefESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void unsetBusidref()
  {
    String oldBusidref = busidref;
    boolean oldBusidrefESet = busidrefESet;
    busidref = BUSIDREF_EDEFAULT;
    busidrefESet = false;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.UNSET, XmlPackage.LISTENER__BUSIDREF, oldBusidref, BUSIDREF_EDEFAULT, oldBusidrefESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isSetBusidref()
  {
    return busidrefESet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isIsGateway()
  {
    return isGateway;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setIsGateway(boolean newIsGateway)
  {
    boolean oldIsGateway = isGateway;
    isGateway = newIsGateway;
    boolean oldIsGatewayESet = isGatewayESet;
    isGatewayESet = true;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, XmlPackage.LISTENER__IS_GATEWAY, oldIsGateway, isGateway, !oldIsGatewayESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void unsetIsGateway()
  {
    boolean oldIsGateway = isGateway;
    boolean oldIsGatewayESet = isGatewayESet;
    isGateway = IS_GATEWAY_EDEFAULT;
    isGatewayESet = false;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.UNSET, XmlPackage.LISTENER__IS_GATEWAY, oldIsGateway, IS_GATEWAY_EDEFAULT, oldIsGatewayESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isSetIsGateway()
  {
    return isGatewayESet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getMaxThreads()
  {
    return maxThreads;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMaxThreads(int newMaxThreads)
  {
    int oldMaxThreads = maxThreads;
    maxThreads = newMaxThreads;
    boolean oldMaxThreadsESet = maxThreadsESet;
    maxThreadsESet = true;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, XmlPackage.LISTENER__MAX_THREADS, oldMaxThreads, maxThreads, !oldMaxThreadsESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void unsetMaxThreads()
  {
    int oldMaxThreads = maxThreads;
    boolean oldMaxThreadsESet = maxThreadsESet;
    maxThreads = MAX_THREADS_EDEFAULT;
    maxThreadsESet = false;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.UNSET, XmlPackage.LISTENER__MAX_THREADS, oldMaxThreads, MAX_THREADS_EDEFAULT, oldMaxThreadsESet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isSetMaxThreads()
  {
    return maxThreadsESet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, XmlPackage.LISTENER__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case XmlPackage.LISTENER__PROPERTY:
        return ((InternalEList<?>)getProperty()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case XmlPackage.LISTENER__PROPERTY:
        return getProperty();
      case XmlPackage.LISTENER__BUSIDREF:
        return getBusidref();
      case XmlPackage.LISTENER__IS_GATEWAY:
        return isIsGateway() ? Boolean.TRUE : Boolean.FALSE;
      case XmlPackage.LISTENER__MAX_THREADS:
        return new Integer(getMaxThreads());
      case XmlPackage.LISTENER__NAME:
        return getName();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case XmlPackage.LISTENER__PROPERTY:
        getProperty().clear();
        getProperty().addAll((Collection<? extends PropertyType>)newValue);
        return;
      case XmlPackage.LISTENER__BUSIDREF:
        setBusidref((String)newValue);
        return;
      case XmlPackage.LISTENER__IS_GATEWAY:
        setIsGateway(((Boolean)newValue).booleanValue());
        return;
      case XmlPackage.LISTENER__MAX_THREADS:
        setMaxThreads(((Integer)newValue).intValue());
        return;
      case XmlPackage.LISTENER__NAME:
        setName((String)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case XmlPackage.LISTENER__PROPERTY:
        getProperty().clear();
        return;
      case XmlPackage.LISTENER__BUSIDREF:
        unsetBusidref();
        return;
      case XmlPackage.LISTENER__IS_GATEWAY:
        unsetIsGateway();
        return;
      case XmlPackage.LISTENER__MAX_THREADS:
        unsetMaxThreads();
        return;
      case XmlPackage.LISTENER__NAME:
        setName(NAME_EDEFAULT);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case XmlPackage.LISTENER__PROPERTY:
        return property != null && !property.isEmpty();
      case XmlPackage.LISTENER__BUSIDREF:
        return isSetBusidref();
      case XmlPackage.LISTENER__IS_GATEWAY:
        return isSetIsGateway();
      case XmlPackage.LISTENER__MAX_THREADS:
        return isSetMaxThreads();
      case XmlPackage.LISTENER__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (busidref: ");
    if (busidrefESet) result.append(busidref); else result.append("<unset>");
    result.append(", isGateway: ");
    if (isGatewayESet) result.append(isGateway); else result.append("<unset>");
    result.append(", maxThreads: ");
    if (maxThreadsESet) result.append(maxThreads); else result.append("<unset>");
    result.append(", name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //ListenerImpl
